package com.formssi.controller;

import com.formssi.pojo.User2;
import com.formssi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: ajims
 * @time: 2021/6/24 10:27
 *     List<User2> findAllUser();
 *     int save(User2 user2);
 *     int update(User2 user2);
 *     User2 get(Integer id);
 *     int delete(Integer id);
 */
@RestController
public class UserController {

    @Autowired
    @Qualifier("userServiceImpl")
    UserService userService;

//    查询全部用户
    @GetMapping("/findAllUser")
    public List<User2> findAllUser(){
        return userService.findAllUser();
    }

//    根据用户id获取用户信息
    @GetMapping("/get/{id}")
    public User2 get(@PathVariable("id") Integer id){
        return userService.get(id);
    }

//    更新用户
    @PostMapping("/update")
    public Integer update(@Valid User2 user2){
        user2.setModiTime(new Timestamp(new Date().getTime()));
        return userService.update(user2);
    }

//    新增用户
    @PostMapping("/sava")
    public Integer save(@Valid User2 user2){
        Timestamp timestamp = new Timestamp(new Date().getTime());
        user2.setInstData(timestamp);
        return userService.save(user2);
    }

//    删除用户
    @GetMapping("/delete/{id}")
    public Integer delete(@PathVariable("id") Integer id){
        return userService.delete(id);
    }

}
